package cn.jinjimi.app.managers;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;

import cn.jinjimi.app.R;
import cn.jinjimi.app.bean.BundleKey;
import cn.jinjimi.app.entity.PictureShow;
import cn.jinjimi.app.main.activity.PhotoBrowserActivity;
import cn.jinjimi.app.main.activity.PhotoPreviewActivity;

import java.io.Serializable;
import java.util.List;

/**
 * Created by Roy
 * Date: 15/11/10
 */
public class OpenActivityManager {

    private static volatile OpenActivityManager instance = null;

    /* 双重检验锁的懒汉模式的单例模式*/
    public static OpenActivityManager getInstance() {
        if (instance == null) {
            synchronized (OpenActivityManager.class) {
                if (instance == null)
                    instance = new OpenActivityManager();
            }
        }
        return instance;
    }

    /* 打开浏览网页大图的界面（多图） */
    public void startPhotoNormalBrowserActivity(Context context, List<PictureShow> pictureShows, int index, boolean canDownload) {
        Intent intent = new Intent();
        intent.putExtra(BundleKey.PARAM_PICTURE_SHOW, (Serializable) pictureShows);
        intent.putExtra(BundleKey.PARAM_START_INDEX, index);
        intent.putExtra(BundleKey.PARAM_PICTURE_CAN_DOWNLOAD, canDownload);
        intent.setClass(context, PhotoBrowserActivity.class);
        context.startActivity(intent);
        ((Activity) context).overridePendingTransition(R.anim.activity_alpha_scale_in, 0);
    }

    public void startPhotoNormalBrowserActivity(Context context, List<PictureShow> pictureShows, int index) {
        startPhotoNormalBrowserActivity(context, pictureShows, index, false);
    }

    /* 预览本地大图的界面（多图） */
    public void startPhotoPreViewActivity(Context context, List<PictureShow> pictureShows, int index) {
        Intent intent = new Intent();
        intent.putExtra(BundleKey.PARAM_PICTURE_SHOW, (Serializable) pictureShows);
        intent.putExtra(BundleKey.PARAM_START_INDEX, index);
        intent.setClass(context, PhotoPreviewActivity.class);
        context.startActivity(intent);
        ((Activity) context).overridePendingTransition(R.anim.activity_fade_in, 0);
    }
}
